package com.blumov.fastbox.application.services.configuration;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;


/**
 * Contenedor para los servicios de Spring.
 * 
 * @author Bruno Masci
 */
public class ApplicationContainer {
	public static final String[] PATHS = ConfigurationLocations.getPaths();

	private ApplicationContext ctx;
	private static ApplicationContainer instance = null;

	public static synchronized ApplicationContainer getInstance() {

		if (instance == null) {
			instance = new ApplicationContainer();
		}
		
		return instance;
	}

	/*
	 * Metodos del singleton.
	 */

	/**
	 * Default constructor
	 */
	private ApplicationContainer() {
		this.ctx = new ClassPathXmlApplicationContext(PATHS);
	}

	/**
	 * Obtiene un servicio
	 * 
	 * @param name
	 * @return aService que corresponde con name
	 */
	public Object getService(String name) {
		return this.ctx.getBean(name);
	}
}
